﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Treatment Repository
    /// </summary>
    public class TreatmentRepository : ITreatmentRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Treatment Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<Treatment> FindTreatmentByName(string strQuery)
        {
            return _db.Treatments.Where(d => d.Title.Contains(strQuery));
        }

        /// <summary>
        /// Get All Treatment
        /// </summary>
        /// <returns></returns>
        public IQueryable<Treatment> FindAllTreatment()
        {
            return _db.Treatments;
        }

        /// <summary>
        /// Get Treatment by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Treatment GetTreatmentById(int id)
        {
            return _db.Treatments.SingleOrDefault(d => d.TreatmentId == id);
        }

        /// <summary>
        /// Add Treatment in the Database
        /// </summary>
        /// <param name="treatment"></param>
        public void Add(Treatment treatment)
        {
            _db.Treatments.AddObject(treatment);
        }

        /// <summary>
        /// Delete Treatment from Database
        /// </summary>
        /// <param name="treatment"></param>
        public void Delete(Treatment treatment)
        {
            _db.Treatments.DeleteObject(treatment);
        }

        /// <summary>
        /// Save Treatment in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}